package com.listen.common;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class DataBase {
	
	public static ResultSet select(String sql){
		Connection conn = null;
		Statement st = null;
		try {
			conn = GetConnection.getConnection();
			st = conn.createStatement();
			ResultSet rs = st.executeQuery(sql);
			return rs;
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			closed(null,st,conn);
		}
		return null;
	}
	
	public static int update(String sql){
		Connection conn = null;
		Statement st = null;
		try {
			conn = GetConnection.getConnection();
			st = conn.createStatement();
			return st.executeUpdate(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			closed(null,st,conn);
		}
		return 0;
	}
	
	public static void closed(ResultSet rs,Statement st,Connection conn){
		if(rs != null){
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if(st != null){
			try {
				st.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if(conn != null){
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}
